{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "16e0cd3d-419c-49fd-8e17-b65c9931d87b",
   "metadata": {},
   "source": [
    "# Exoplanet"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a2c835d4-62af-4a6f-b4c8-ca8185739fbd",
   "metadata": {},
   "source": [
    "假设我们在太阳系外非常遥远的地方观察太阳，尝试计算探测到地球和木星的可能性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e539c5eb-ab5b-4abe-9e05-d6a542a075f0",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import astropy.units as u\n",
    "import astropy.constants as c\n",
    "import matplotlib.pyplot as plt\n",
    "plt.rcParams[\"font.size\"] = 20"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0551e93a-88d0-4e86-8f2d-f8f465e4b113",
   "metadata": {},
   "source": [
    "以下是地球、木星和太阳的质量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0ca60505-d32e-4e72-a0b2-68dfd45f853a",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$5.9721679 \\times 10^{24} \\; \\mathrm{kg}$"
      ],
      "text/plain": [
       "<<class 'astropy.constants.iau2015.IAU2015'> name='Earth mass' value=5.972167867791379e+24 uncertainty=1.3422009501651213e+20 unit='kg' reference='IAU 2015 Resolution B 3 + CODATA 2018'>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c.M_earth"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a1df86ff-9ef0-402c-ade0-fa9a645fc28b",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$1.8981246 \\times 10^{27} \\; \\mathrm{kg}$"
      ],
      "text/plain": [
       "<<class 'astropy.constants.iau2015.IAU2015'> name='Jupiter mass' value=1.8981245973360505e+27 uncertainty=4.26589589320839e+22 unit='kg' reference='IAU 2015 Resolution B 3 + CODATA 2018'>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c.M_jup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "8fd8787e-bbaa-41f5-b770-b05b0b84dc5a",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$1.9884099 \\times 10^{30} \\; \\mathrm{kg}$"
      ],
      "text/plain": [
       "<<class 'astropy.constants.iau2015.IAU2015'> name='Solar mass' value=1.988409870698051e+30 uncertainty=4.468805426856864e+25 unit='kg' reference='IAU 2015 Resolution B 3 + CODATA 2018'>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c.M_sun"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "f228e44a-be89-4468-88f9-fcc1127e531f",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$6378100 \\; \\mathrm{m}$"
      ],
      "text/plain": [
       "<<class 'astropy.constants.iau2015.IAU2015'> name='Nominal Earth equatorial radius' value=6378100.0 uncertainty=0.0 unit='m' reference='IAU 2015 Resolution B 3'>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c.R_earth"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "8d51b797-879d-48aa-8dcf-d1cf4a8e1f87",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$71492000 \\; \\mathrm{m}$"
      ],
      "text/plain": [
       "<<class 'astropy.constants.iau2015.IAU2015'> name='Nominal Jupiter equatorial radius' value=71492000.0 uncertainty=0.0 unit='m' reference='IAU 2015 Resolution B 3'>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c.R_jup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "45bc1cb4-4af7-4819-892a-5b1915a7d945",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$6.957 \\times 10^{8} \\; \\mathrm{m}$"
      ],
      "text/plain": [
       "<<class 'astropy.constants.iau2015.IAU2015'> name='Nominal solar radius' value=695700000.0 uncertainty=0.0 unit='m' reference='IAU 2015 Resolution B 3'>"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c.R_sun"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "df6d4f8f-3f76-4baf-8c76-764cac3c6e7c",
   "metadata": {},
   "source": [
    "关于引力的常数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "2b79e11c-f396-4c90-aadb-77d5584bddb1",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$6.6743 \\times 10^{-11} \\; \\mathrm{\\frac{m^{3}}{kg\\,s^{2}}}$"
      ],
      "text/plain": [
       "<<class 'astropy.constants.codata2018.CODATA2018'> name='Gravitational constant' value=6.6743e-11 uncertainty=1.5e-15 unit='m3 / (kg s2)' reference='CODATA 2018'>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c.G"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "4ecacf2f-9dac-4d19-8a3c-502a0cc7637b",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$1.3271244 \\times 10^{20} \\; \\mathrm{\\frac{m^{3}}{s^{2}}}$"
      ],
      "text/plain": [
       "<<class 'astropy.constants.iau2015.IAU2015'> name='Nominal solar mass parameter' value=1.3271244e+20 uncertainty=0.0 unit='m3 / s2' reference='IAU 2015 Resolution B 3'>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c.GM_sun"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "747bca66-89b7-4570-8c5b-cce7a794e0bd",
   "metadata": {},
   "source": [
    "计算凌星法观测到的地球和木星导致观测到的太阳光度变化为"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "46897713-a172-4b7d-8f46-bc05b1ad78f9",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$8.4050179 \\times 10^{-5} \\; \\mathrm{}$"
      ],
      "text/plain": [
       "<Quantity 8.40501788e-05>"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c.R_earth**2/c.R_sun**2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "2d484b5e-565b-4b85-9815-336ae003ac3d",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "text/latex": [
       "$0.010560169 \\; \\mathrm{}$"
      ],
      "text/plain": [
       "<Quantity 0.01056017>"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c.R_jup**2/c.R_sun**2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b0e947da-883c-4c75-9677-a84cf723296f",
   "metadata": {
    "tags": []
   },
   "source": [
    "## 计算凌星的时长"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5d297bdf-893d-4b5f-bbbc-fd3ae685654f",
   "metadata": {
    "tags": []
   },
   "source": [
    "### Earth"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "8593f6b4-7b00-4362-966b-9a09137ff6bd",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "29.78469182967693 km / s 46715.27266277216 s\n"
     ]
    }
   ],
   "source": [
    "sma = 1*u.AU\n",
    "\n",
    "v_planet = np.sqrt(c.GM_sun/(sma)).to(u.km/u.s)\n",
    "t_transit = 2*c.R_sun/v_planet\n",
    "print(v_planet, t_transit.to(u.s))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "905c1167-92ef-4b22-853a-a511de97ab65",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "428.28040904186736 s\n"
     ]
    }
   ],
   "source": [
    "t_ingress = 2*c.R_earth/v_planet\n",
    "print(t_ingress.to(u.s))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0517fed5-d24e-4a50-8628-a284735858e1",
   "metadata": {},
   "source": [
    "### Jupiter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "aec8ca07-0fdf-4d20-b056-c50b0458e1ae",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "13.061451410903352 km / s 106527.21173379678 s\n"
     ]
    }
   ],
   "source": [
    "sma = 5.2*u.AU\n",
    "\n",
    "v_planet = np.sqrt(c.GM_sun/(sma)).to(u.km/u.s)\n",
    "t_transit = 2*c.R_sun/v_planet\n",
    "print(v_planet, t_transit.to(u.s))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "bff89d66-7081-425d-bc7c-ad3ff82322b5",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10947.022310295528 s\n"
     ]
    }
   ],
   "source": [
    "t_ingress = 2*c.R_jup/v_planet\n",
    "print(t_ingress.to(u.s))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a4a4795a-588b-46e7-9950-3aa7cedf102f",
   "metadata": {
    "tags": []
   },
   "source": [
    "## 计算视向速度的变化"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "257ffc76-77b1-4d4d-9bc8-d0ddbd7a6cf2",
   "metadata": {
    "tags": []
   },
   "source": [
    "### Earth"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "7b01e02a-c871-44a1-a9ad-3ce180de85f6",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "v_planet:  29.78469182967693 km / s\n",
      "v_sun:  0.08945800466923791 m / s\n"
     ]
    }
   ],
   "source": [
    "sma = 1*u.AU\n",
    "mass = c.M_earth\n",
    "\n",
    "v_planet = np.sqrt(c.GM_sun/(sma)).to(u.km/u.s)\n",
    "v_sun = v_planet*mass/c.M_sun\n",
    "print(\"v_planet: \", v_planet)\n",
    "print(\"v_sun: \", v_sun.to(u.m/u.s))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6fc872e5-25bd-48ea-b071-7b0b4cdd4816",
   "metadata": {
    "tags": []
   },
   "source": [
    "### Jupiter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "03c484ad-b992-4374-b0d3-ddcfea461016",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "v_planet:  13.061451410903352 km / s\n",
      "v_sun:  12.468386204118843 m / s\n"
     ]
    }
   ],
   "source": [
    "sma = 5.2*u.AU\n",
    "mass = c.M_jup\n",
    "\n",
    "v_planet = np.sqrt(c.GM_sun/(sma)).to(u.km/u.s)\n",
    "v_sun = v_planet*mass/c.M_sun\n",
    "print(\"v_planet: \", v_planet)\n",
    "print(\"v_sun: \", v_sun.to(u.m/u.s))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d115043b-7c92-4a7f-bf6a-9e3952ca45cc",
   "metadata": {
    "tags": []
   },
   "source": [
    "### Jupiter on Earth's orbit"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "36e8cd8c-f18e-4463-8472-25c9c8096f92",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "v_planet:  29.78469182967693 km / s\n",
      "v_sun:  28.43229508116286 m / s\n"
     ]
    }
   ],
   "source": [
    "sma = 1*u.AU\n",
    "mass = c.M_jup\n",
    "\n",
    "v_planet = np.sqrt(c.GM_sun/(sma)).to(u.km/u.s)\n",
    "v_sun = v_planet*mass/c.M_sun\n",
    "print(\"v_planet: \", v_planet)\n",
    "print(\"v_sun: \", v_sun.to(u.m/u.s))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "67f002d6-803f-4f86-a370-402cf165aad8",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
